using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using OpenComposite.Base.Designer;
using OpenComposite.EII.Designer.Generic;

namespace OpenComposite.EII.Designer.ITStructure
{
	public class ITObjectSymbol : ConnectedSymbol
	{
		#region Initialization
		public ITObjectSymbol()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			//this.Name = "itObject" + GetCount(typeof(ITObjectSymbol));
			this.Text = "ITObject";

			this.Size = new Size(70, 50);
			this.MinimumSize = new Size(70, 50);

			this.Border = BorderType.RoundedRectangle;
			this.BorderColor = Color.Blue;
			this.BorderWidth = 4;

			this.BackBrushMode = BackgroundBrushMode.LinearGradient;
			this.BackColor = Color.LightSkyBlue;
			this.BackColor2 = Color.White;
			this.BackLinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal;

			this.NameTextBox.BorderVisibilityStyle = BorderVisibilityStyle.MouseOverAndFocus;
			this.NameTextBox.BackColor = Color.Transparent;

			//_iStartConnectors = 0;
			//_iEndConnectors = 0;

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Override

		#region Properties
		public override bool CanFocused
		{
			get
			{
				return true;
			}
		}
		public override bool CanMove
		{
			get
			{
				return true;
			}
		}
		public override bool CanResize
		{
			get
			{
				return true;
			}
		}
		public override bool CanSelect
		{
			get
			{
				return true;
			}
		}
		public override bool IsContainer
		{
			get
			{
				return false;
			}
		}
		public override bool NoClip
		{
			get
			{
				return false;
			}
		}
		#endregion

		#region Drag & Drop
		public override object GetDragObject(Point location, System.Windows.Forms.MouseButtons button)
		{
			return this;
		}
		public override bool IsDropAllowed(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			return ( ( obj is ITObjectSymbol || obj is ExternalSymbol || obj is SCA.ServiceComponentSymbol ) && obj != this &&
				button == System.Windows.Forms.MouseButtons.Right );
		}
		public override void DropObject(object obj, Point location, System.Windows.Forms.MouseButtons button)
		{
			if ( this.IsDropAllowed(obj, location, button) ) {
				this.DesignerViewControl.AddRoute((DesignerControl)obj, this);
			}
		}
		#endregion

		#endregion

		#region IConnectorFactory Members

		#region Old Create Route Start / End
		//public override bool CreateRouteStart(DesignerControl controlEnd, out IConnector connector,
		//    out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
		//    out RouteDockDirection dockStart, out RouteDockDirection dockEnd)
		//{
		//    bool bOK = base.CreateRouteStart(controlEnd, out connector, out cap, out customcap, out dockStart, out dockEnd);

		//    EllipseConnector c = new EllipseConnector();
		//    c.Location = new Point(this.Width - (int)( c.Width / 2 ) - 5, 5 + ( ( c.Height + 5 ) * _iStartConnectors ));
		//    c.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right;
		//    this.Controls.Add(c);
		//    _iStartConnectors++;

		//    connector = c;
		//    cap = LineCap.RoundAnchor;
		//    customcap = null;

		//    dockStart = RouteDockDirection.Right;
		//    dockEnd = RouteDockDirection.Left;

		//    return bOK;
		//}
		//public override bool CreateRouteEnd(DesignerControl controlStart, out IConnector connector,
		//    out System.Drawing.Drawing2D.LineCap cap, out System.Drawing.Drawing2D.CustomLineCap customcap,
		//    out RouteDockDirection dockStart, out RouteDockDirection dockEnd)
		//{
		//    bool bOK = base.CreateRouteEnd(controlStart, out connector, out cap, out customcap, out dockStart, out dockEnd);

		//    if ( controlStart is SCA.ServiceComponentSymbol ) {
		//        //cap = System.Drawing.Drawing2D.LineCap.Custom;
		//        //GraphicsPath path = new GraphicsPath();
		//        //path.AddRectangle(new RectangleF(-2.5f, -2f, 5f, 4f));
		//        //customcap = new System.Drawing.Drawing2D.CustomLineCap(path, null);
		//        cap = LineCap.DiamondAnchor;
		//        customcap = null;
		//    } else {
		//        //RectangleConnector c = new RectangleConnector();
		//        //c.Location = new Point(c.Left - (int)( c.Width / 2 ) - 5, 5 + ( ( c.Height + 5 ) * _iEndConnectors ));
		//        //c.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left;
		//        //this.Controls.Add(c);
		//        //_iEndConnectors++;

		//        //connector = c;

		//        dockStart = RouteDockDirection.Right;
		//        dockEnd = RouteDockDirection.Left;
		//    }
		//    return bOK;
		//}
		#endregion
		protected override RouteDockDirection GetStartDockDirection(DesignerControl controlEnd, RouteDockDirection defaultDock)
		{
			if ( controlEnd is ITObjectSymbol )
				return RouteDockDirection.Right;
			else
				return base.GetStartDockDirection(controlEnd, defaultDock);
		}
		protected override RouteDockDirection GetEndDockDirection(DesignerControl controlStart, RouteDockDirection defaultDock)
		{
			if ( controlStart is ITObjectSymbol )
				return RouteDockDirection.Left;
			else
				return base.GetEndDockDirection(controlStart, defaultDock);
		}
		protected override Connector GetEndConnector(DesignerControl controlStart)
		{
			Connector c = base.GetEndConnector(controlStart).Clone() as Connector;
			if ( controlStart is SCA.ServiceComponentSymbol )
				c.BackColor = Color.DarkBlue;
			return c;
		}

		#endregion

		#endregion

		#region Private Members

		#region Variables
		//private int _iStartConnectors;
		//private int _iEndConnectors;
		#endregion

		#endregion
	}
}
